/*
 * Copyright (C) 2012 Martin Wilsdorf <mwjutils-api@googlecode.com>.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 */

package com.google.mwjutils.xcode;

/**
 *
 * @author Martin Wilsdorf <mwjutils-api@googlecode.com>
 */
public class XList implements YList {
    private Object data = null;
    private XList  next = null;

    @Override
    public XList insert() {
        XList li = new XList();
        li.next = next;
        next = li;
        return this;
    }
    
    public XList insert(Object o) {
        insert();
        next.data = o;
        return this;
    }
    
    public boolean isEmpty() {
        return (next == null);
    }

    @Override
    public int length() {
        if(isEmpty()) {
            return 0;
        }
        else {
            return 1+next.length();
        }
    }

    @Override
    public XList append() {
        if(isEmpty()) {
            next = new XList();
            return next;
        } else {
            return next.append();
        }
    }

    public XList append( Object o ) {
        if(isEmpty()) {
            next = new XList();
            
            return next;
        } else {
            return next.append();
        }
    }

    @Override
    public YList delete(Object o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
